﻿// Autore: Mattia Barrasso

using RecipesManager.Data;
using White.Core;
using White.Core.UIItems;
using White.Core.UIItems.ListBoxItems;
using White.Core.UIItems.WindowItems;

namespace RecipesManager.Specs.Ricetta
{
    class RicettaBDD
    {
        protected Window MainWindow;
        protected Application Application;
        protected readonly string RecipeManagerTitle = "Gestione Ricette";

        protected Button NewRecipe;
        protected Button RemoveRecipe;
        protected Button BackToMainMenu;
        protected ListBox Recipes;

        protected TextBox RecipeName;
        protected TextBox Source;
        protected ComboBox Portions;
        protected ComboBox Hours;
        protected ComboBox Minutes;
        protected ComboBox Units;
        protected Button SaveRecipe;

        protected void SetUpScenario()
        {
            Manager.ClearDatabase();
            Manager.Measures.Add("grammi", "gr", MeasureType.Weight, MeasureFamily.Metric, 1);
            Manager.Measures.Add("PesoTest", "PT", MeasureType.Weight, MeasureFamily.Metric, 1);
            Application = Application.Launch(@"..\..\..\RecipesManager\bin\x86\WhiteTesting\RecipesManager.exe");
            MainWindow = Application.GetWindow("Recipes Manager");
        }

        protected void TearDownScenario()
        {
            Manager.ClearCache();
            Manager.ClearDatabase();
            Application.Kill();
        }

        protected void GetRecipeUi()
        {
            NewRecipe = MainWindow.Get<Button>("bt_add");
            RemoveRecipe = MainWindow.Get<Button>("bt_delete");
            BackToMainMenu = MainWindow.Get<Button>("bt_back");
            Recipes = MainWindow.Get<ListBox>("lb_items");
        }

        protected void GetSingleRecipeUi()
        {
            RecipeName = MainWindow.Get<TextBox>("tb_nomeRicetta");
            SaveRecipe = MainWindow.Get<Button>("bt_salva");
            Source = MainWindow.Get<TextBox>("tb_fonteOriginale");
            Hours = MainWindow.Get<ComboBox>("cb_tempoOre");
            Minutes = MainWindow.Get<ComboBox>("cb_tempoMin");
            Portions = MainWindow.Get<ComboBox>("cb_numeroPorzioni");
            Units = MainWindow.Get<ComboBox>("cb_famigliUnitaMisura");
        }

        protected void NavigateToRecipes()
        {
            MainWindow.Get<Button>("ricette").Click();
            MainWindow = Application.GetWindow(RecipeManagerTitle);
        }

        protected void NavigateToMainMenu()
        {
            MainWindow.Get<Button>("bt_back").Click();
            MainWindow = Application.GetWindow("Recipes Manager");
        }
    }
}
